<template>
    <el-table class="custom-border-table" :data="tableData" style="width: 100%;margin-bottom: 20px;">
        <el-table-column prop="order_time" label="时间"  />
        <el-table-column prop="declare_content" label="报修数量"  />
        <el-table-column prop="order_warte" label="水费充值"  />
        <el-table-column prop="order_dian" label="电费充值"  />
    </el-table>

</template>

<script setup name="menu">
import { onMounted, ref, reactive } from "vue";
import { getDataReport ,getOrderList,getDeclareInfoAll} from "@/api/admin/home";

onMounted(() => {
    getData();
});
function uniqueArray(arr) {  
    return Array.from(new Set(arr));  
} 
const tableData = ref([]);
const getData = async () => {
    try {
        const res = await getOrderList();
        const res1 = await getDeclareInfoAll();
        if(res.data.code === 200 && res1.data.code === 200){
            let time = res.data.data.map(it=>it.order_time.slice(0,10));
            let newTime = uniqueArray(time)
            let shui = res.data.data.filter(it=>it.order_type === 0  );
            let dian = res.data.data.filter(it=>it.order_type === 1  );
            
            let newArr = 0;
            let DianNewArr = 0;
            shui.forEach((it)=>{
                newArr += Number(it.order_pay);
            });
            dian.forEach((it)=>{
                DianNewArr += Number(it.order_pay);
            });
            let result = [ {
                order_time:newTime,
                order_warte:newArr,
                order_dian:DianNewArr,
                declare_content:res1.data.data.length
            }]
            tableData.value = [...result];
            
        }else{
            ElNotification({
                message: "获取信息失败 ",
                type: "error",
                duration: 3000
            });
        }
       
        
        // if (res.data.code === 200) {
        //     console.log('1111', tableData);
        //     tableData.value = [...res.data.data];

        // } else {
        //     ElNotification({
        //         message: "获取信息失败 ",
        //         type: "error",
        //         duration: 3000
        //     });
        // }
    } catch (error) {
        console.log(error);
    }
};
</script>

<style lang="scss">
    .custom-border-table .el-table__header-wrapper th,  
    .custom-border-table .el-table__body-wrapper tr td {  
        border: 1px solid black;
    }

    .el-table {
        --el-table-tr-bg-color: var(--el-color-success-light-9);
    }
</style>
